<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取当前资源使用状况</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.getrusage" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">getrusage</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">getrusage</span> &mdash; <span class="dc-title">获取当前资源使用状况</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.getrusage-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>getrusage</strong></span>
    ([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$who</code><span class="initializer"> = 0</span></span>
  ] ) : <span class="type">array</span></div>

  <p class="para rdfs-comment">
   这是 <strong class="command">getrusage(2)</strong> 的接口。它返回了调用自系统的数据。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.getrusage-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">who</code></dt>

     <dd>

      <p class="para">
       如果 <code class="parameter">who</code> 是 1，getrusage 会使用
       <strong><code>RUSAGE_CHILDREN</code></strong> 来调用。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.getrusage-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回了一个包含系统返回数据的关联数组。所以条目均可通过文档中字段的名称来访问。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.getrusage-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-511">
    <p><strong>Example #1 <span class="function"><strong>getrusage()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dat&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">getrusage</span><span style="color: #007700">();<br />echo&nbsp;</span><span style="color: #0000BB">$dat</span><span style="color: #007700">[</span><span style="color: #DD0000">"ru_nswap"</span><span style="color: #007700">];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;number&nbsp;of&nbsp;swaps<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$dat</span><span style="color: #007700">[</span><span style="color: #DD0000">"ru_majflt"</span><span style="color: #007700">];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;number&nbsp;of&nbsp;page&nbsp;faults<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$dat</span><span style="color: #007700">[</span><span style="color: #DD0000">"ru_utime.tv_sec"</span><span style="color: #007700">];&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;user&nbsp;time&nbsp;used&nbsp;(seconds)<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$dat</span><span style="color: #007700">[</span><span style="color: #DD0000">"ru_utime.tv_usec"</span><span style="color: #007700">];&nbsp;</span><span style="color: #FF8000">//&nbsp;user&nbsp;time&nbsp;used&nbsp;(microseconds)<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.getrusage-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.0.0</td>
       <td>
        此函数现在开始支持 Windows。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 notes" id="refsect1-function.getrusage-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    在 Windows 上 <span class="function"><strong>getrusage()</strong></span> 仅会返回以下类型：
   </p>
   <p class="para">
    <ul class="simplelist">
     <li class="member"><em>&quot;ru_stime.tv_sec&quot;</em></li>
     <li class="member"><em>&quot;ru_stime.tv_usec&quot;</em></li>
     <li class="member"><em>&quot;ru_utime.tv_sec&quot;</em></li>
     <li class="member"><em>&quot;ru_utime.tv_usec&quot;</em></li>
     <li class="member">
      <em>&quot;ru_majflt&quot;</em> (only if <code class="parameter">who</code> is 
      <strong><code>RUSAGE_SELF</code></strong>)
     </li>
     <li class="member">
      <em>&quot;ru_maxrss&quot;</em> (only if <code class="parameter">who</code> is 
      <strong><code>RUSAGE_SELF</code></strong>)
     </li>
    </ul>
   </p>
   <p class="para">
    If <span class="function"><strong>getrusage()</strong></span> is called with <code class="parameter">who</code> 
    set to <em>1</em> (<strong><code>RUSAGE_CHILDREN</code></strong>), then 
    resource usage for threads are collected (meaning that internally the function 
    is called with <strong><code>RUSAGE_THREAD</code></strong>).
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    在 BeOS 2000，仅会返回以下类型：
   </p>
   <p class="para">
    <ul class="simplelist">
     <li class="member"><em>&quot;ru_stime.tv_sec&quot;</em></li>
     <li class="member"><em>&quot;ru_stime.tv_usec&quot;</em></li>
     <li class="member"><em>&quot;ru_utime.tv_sec&quot;</em></li>
     <li class="member"><em>&quot;ru_utime.tv_usec&quot;</em></li>
    </ul>
   </p>
  </p></blockquote>
 </div>



 <div class="refsect1 seealso" id="refsect1-function.getrusage-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">你系统上 <strong class="command">getrusage(2)</strong> 的 man page</li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>